package ruifight.member.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import ruifight.member.model.ContactMy;
import ruifight.member.model.ContactMyExample;
import ruifight.member.service.ContactMyService;


@Controller
@RequestMapping("/interface")
public class ContactMyController {

	private static final Logger logger = LoggerFactory.getLogger(ContactMyController.class);

	@Autowired
	public ContactMyService contactMyService;

	/**
	 * 获取联系我们信息
	 * @return
	 */
	@RequestMapping("/getContactMyInfo")
	@ResponseBody
	public ContactMy getContactMyInfo() {
		ContactMy contactMy= contactMyService.selectOneByExampleWithBLOBs(new ContactMyExample());
		return contactMy;
	}

	/**
	 * 添加联系我们信息
	 * @param contactMy
	 * @return
	 */
	@RequestMapping("/addOrUpdateContactMyInfo")
	@ResponseBody
	public  Map<String, Object> addOrUpdateContactMyInfo(@RequestBody ContactMy contactMy) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			if(contactMy.getContactMyId()==null){
				contactMyService.insertSelective(contactMy);
			}else{
				contactMyService.updateByPrimaryKeySelective(contactMy);
			}
			map.put("state", 1);
			map.put("msg", "添加成功");
		} catch (Exception e) {
			map.put("state", 0);
			map.put("msg", "添加失败");
			e.printStackTrace();
		}
		return map;
	}
}
